<?php
class Arm_Form_Element_Date extends Zend_Form_Element
{
  public function init(){
    parent::init();

    $this ->addValidator(new Zend_Validate_Regex('/^(((0[1-9]|[12]\d|3[01])\/(0[13578]|1[02])\/((1[6-9]|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)\/(0[13456789]|1[012])\/((1[6-9]|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])\/02\/((1[6-9]|[2-9]\d)\d{2}))|(29\/02\/((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$/'));
    $this ->setOptions(array(
      'size'        => 11,
      'maxlength'   => 10,
      'onkeyup'     => 'formDateMasc(this.id)',
      'onblur'      => 'validateDate(this.id)',
      'class'       => 'formDatePicker',
    ));

    $this->addErrorMessage('Data inválida! Utilize formato dd/mm/aaaa');
    $this ->addFilter('StripTags');
    $this ->addFilter('StringTrim');
  }

  /**
   *    Prepara o valor, convertendo de data do banco para formato humano,
   *    após realiza o parent::setValue()
   *    @param  string  $value
   */
  public function setValue($value){
    $value  = Arm_Tools::dateToScreen($value);

    parent::setValue($value);
  }
}
